<?php

namespace app\admin\controller\send;

use app\common\controller\AdminController;
use app\common\services\annotation\ControllerAnnotation;
use app\common\services\annotation\NodeAnnotation;
use app\common\DnfmailController;

use support\Request; //请求类
use support\Response; //请求类
use think\facade\Db; //数据库类
use think\App; //初始化
use think\Exception; //异常
/**
 * @ControllerAnnotation(title="send_log")
 */
class LogController extends AdminController
{

    public function initialize()
    {
        parent::initialize();
        $this->model = new \app\admin\model\SendLog();
    }
    
    public function sendbf(Request $request){
	    if(!$request->get('id')){
            return $this->error("参数错误");
        }
        $info = DB::name('send_log')->where('id',$request->get('id'))->find();
        if($info['status'] == 1){return $this->error('未失败,不可补发');}
        $dnfmailController = new DnfmailController();
        $retu = $dnfmailController->senddnfmail($info['noid'],$info['wupid'],$info['num'],$info['hztype'],$info['hznum'],$info['gold'],$info['fz'],$info['dz'],$info['qh'],$info['info'],$info['title'],$info['account'],$info['gamename'],$request->get('id'));
        if($retu == "1"){
            return $this->success('补发成功');
        }else{
            return $this->error('补发失败');
        }
    }
    public function index(Request $request): Response
    {
        if (!$request->isAjax()) return $this->fetch('admin/send/log/index');
        if ($request->input('selectFields')) {
            return $this->selectList();
        }
        list($page, $limit, $where) = $this->buildTableParams();
        $count = $this->model->where($where)->count();
        $list  = $this->model->where($where)->order($this->order)->page($page, $limit)->select()->toArray();
        $data  = [
            'code'  => 0,
            'msg'   => '',
            'count' => $count,
            'data'  => $list,
        ];
        return json($data);
    }
}
